/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package encodingfixer;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
import java.util.logging.Logger;

/**
 *
 * @author mesticora at gmail dot com
 */
public class efWriteLog {    
    public static Logger logger;
/**
 * Constructor
 *
 * @param fileName - path to file
 */
    public efWriteLog() {
        try {
            boolean append = true;
            FileHandler fh = new FileHandler("logfile.log", append);
            fh.setFormatter(new Formatter() {
                public String format(LogRecord rec) {
                    StringBuffer buf = new StringBuffer(1000);                    
                    buf.append(new java.util.Date());                    
                    buf.append(" [");
                    buf.append(rec.getLevel());
                    buf.append("]: ");
                    buf.append(formatMessage(rec));
                    buf.append('\n');
                    return buf.toString();
            }
          });
          logger = Logger.getLogger("efWriteLog");
          logger.addHandler(fh);
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }
    
/**
 *  Writes log to file
 * @param messageText message to log
 * @param logLevel log level: 0 - system, 1 - waring, 2 - info
 *
 */
   public void log(String messageText, int logLevel) {
       switch(logLevel) {
           case 0: logger.severe(messageText);break;
           case 1: logger.warning(messageText);break;
           case 2: logger.info(messageText);break;
       }
   }

}